/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geotools.geosearch;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author olegelantsev
 */
public class MainTest {
public static int trialsCount = 10;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        MainTest test = new MainTest();
        test.testGetPathAsynch();
        System.exit(0);
    }

    public void testGetPathAsynch() {
        final double[] points = new double[14];
        points[0] = 346459.01031933835;
        points[1] = 6110859.318814812;
        points[2] = 346473.15329153894;
        points[3] = 6110973.136635963;
        points[4] = 345491.5452378177;
        points[5] = 6110986.9159264965;
        points[6] = 345871.3886644124;
        points[7] = 6110625.5927172275;
        points[8] = 345491.5452378177;
        points[9] = 6110625.5927172275;
        points[10] = 346473.15329153894;
        points[11] = 6110625.5927172275;
        points[12] = 345871.0886644124;
        points[13] = 6110970.318814812;
        /*
        ExecutorService pool = Executors.newFixedThreadPool(10);
        CompletionService<String> compService = new ExecutorCompletionService<String>(pool);

        for (int i = 0; i < trialsCount; ++i) {

            compService.submit(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    String result = GuideSingleton.getPathJSON(points);
                    return result;
                }
            });
        }


        for (int i=0; i<trialsCount; ++i) {
            try {
                Future<String> take = compService.take();
                System.out.println(i+'\n');
            } catch (InterruptedException ex) {
                Logger.getLogger(MainTest.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        */
        Map<String, Object> connectionParameters = new HashMap<String, Object>();
            connectionParameters.put("dbtype", "postgis");
            connectionParameters.put("host", "localhost");
            connectionParameters.put("port", "5432");
            connectionParameters.put("database", "gis");
            connectionParameters.put("user", "oleg");
            connectionParameters.put("passwd", "password");
            connectionParameters.put("scheme", "public");
        Guide guide  = Guide.fromDB(connectionParameters);
        for (int i = 0; i < trialsCount; ++i) {
            String result = guide.guidanceJSONMultiple(points);
            System.out.println(result);
        }
        System.out.println("async ended");
    }

}
